//
//  DDTNetworkTool.swift
//  weibo
//
//  Created by mac on 16/9/24.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import AFNetworking
 /// 网络请求方法枚举
enum DDTNetworkMethod: String {
    case GET = "GET"
    case POST = "POST"
}


class DDTNetworkTool: NSObject {

    static let sharedInstance: DDTNetworkTool = DDTNetworkTool()
    var afnManager: AFHTTPSessionManager
    
    private override init() {
        let baseURL = NSURL(string: "ttps://api.weibo.com/")
        afnManager = AFHTTPSessionManager(baseURL: baseURL)
    
        afnManager.responseSerializer.acceptableContentTypes?.insert("text/plain")
    }
    
    
    
    func request(method:DDTNetworkMethod, URLString:String, parameters:AnyObject?, progress: ((NSProgress) -> Void)?, sussess: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)?) -> Void {
        
        switch method {
            
        case .GET:
            afnManager.GET(URLString, parameters: parameters, progress: progress, success: sussess, failure: failure)
            break
        case .POST:
             afnManager.POST(URLString, parameters: parameters, progress: progress, success: sussess, failure: failure)
            break
            
        }
        
        
        
    }
}











